package com.quartz.image;


import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: lixiao
 * Created Date: 2020/9/15 15:54
 */
public class sms {

    /** 日志记录 */

    private static final String NAME;
    private static final String PWD;
    private static final String SIGN;
    /** 普通短信发送 */
    private static final String TYPE_1 = "pt";

    private static final String URL = "http://api.daiyicloud.com/asmx/smsservice.aspx";

    static {
//		PropertiesUtil pu = new PropertiesUtil("other_interface.properties");
//		NAME = pu.readProperty("sms.name");
//		PWD = pu.readProperty("sms.pwd");
//		SIGN = pu.readProperty("sms.sign");
        NAME ="lixiao";
        PWD ="D8D32C5D3B658679C953B215B365";
        SIGN = "上海卓繁";
    }

    /**
     * 发送短信
     *
     * @param phone
     *            手机号码
     * @param message
     *            发送sms信息
     * @return true=发送成功，false=发送失败
     */
    public static boolean sendSms(String phone, String message) {
        HttpRequester req = new HttpRequester();
        Map<String, String> param = new HashMap<>(6);
        try {
            param.put("name", NAME);
            param.put("pwd", PWD);
            param.put("content",URLEncoder.encode(message.toString(), "UTF-8"));
            param.put("mobile", phone);
            param.put("sign", URLEncoder.encode(SIGN, "UTF-8"));
            param.put("type", TYPE_1);
            HttpRespons resp = req.sendPost(URL, param);
            String content = resp.getContent();
            if (content!=null) {
                String[] ret = content.split(",");
                String zero = "0";
                if (zero.equals(ret[0])) {
                    return true;
                }
            }
        } catch (Exception e) {
            System.out.println("发送短信出现错误，" + e.getMessage());
        }
        return false;
    }

    public static void main(String[] args) {
        sms.sendSms("17601307645","lixiao111111111");
    }
}